package com.jsyl.lwbk.web.controller.business;

import com.jsyl.lwbk.business.domain.ClassPlan;
import com.jsyl.lwbk.business.service.ClassPlanService;
import com.jsyl.lwbk.common.core.controller.BaseController;
import com.jsyl.lwbk.common.core.domain.AjaxResult;
import com.jsyl.lwbk.common.core.page.TableDataInfo;
import com.jsyl.lwbk.common.utils.DateUtils;
import com.jsyl.lwbk.framework.util.ShiroUtils;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 训练计划
 */
@Api(value = "训练计划")
@Controller
@RequestMapping("/business/classPlan")
public class ClassPlanController extends BaseController {

    private String prefix = "business/classPlan";

    @Autowired
    ClassPlanService classPlanService;

    /**
     * 页面跳转-项目计划主页
     * @param mmap
     * @return
     */
    @GetMapping()
    public String child(ModelMap mmap) {
        return prefix + "/classPlanList";
    }

    /**
     * 页面跳转-新增项目计划
     */

    @GetMapping("/add")
    public String add()
    {
        return prefix + "/addClassPlan";
    }


    /**
     *
     *
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo findList(ClassPlan classPlan) {
        startPage();
        List<ClassPlan> list = classPlanService.findList(classPlan);
        return getDataTable(list);
    }

    /**
     *
     *
     * @param classPlan
     * @return
     */
    @PostMapping("/checkPlanNameUnique")
    @ResponseBody
    public String checkPlanNameUnique(ClassPlan classPlan) {
        Integer temp =classPlanService.checkPlanNameUnique(classPlan);
        return temp.toString() ;
    }
    /**
     * 新增
     *
     * @param classPlan
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addClassPlan(ClassPlan classPlan) {
        classPlan.setCreateUser(ShiroUtils.getLoginName());
        classPlan.setUpdateUser(ShiroUtils.getLoginName());
        classPlan.setUpdateTime(DateUtils.getNowDate());
        classPlanService.addClassPlan(classPlan);
        return success();
    }

    /**
     * 启用/停用
     *
     * @param classPlan
     * @return
     */
    @PostMapping("/updateStatus")
    @ResponseBody
    public AjaxResult updateStatus(@RequestBody ClassPlan classPlan) {
        classPlan.setUpdateUser(ShiroUtils.getLoginName());
        classPlan.setUpdateTime(DateUtils.getNowDate());
        classPlanService.updateStatus(classPlan);
        return success();
    }

}
